const app = getApp();
var revenueApi = require('../../script/revenue.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navHeight: app.globalData.statusBarHeight,
    CurrentPage: 1,
    PageSize: 20,
    HasNextPage: true,
    dataList: [],
    noData: false,
    isReachBottom: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getDataList(true);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    wx.showNavigationBarLoading();
    this._refreshData();
    wx.hideNavigationBarLoading();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      isReachBottom: true
    });
    if (this.data.HasNextPage) {
      this.setData({
        CurrentPage: this.data.CurrentPage + 1
      })
      this.getDataList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  _refreshData() {
    this.setData({
      CurrentPage: 1,
      HasNextPage: true,
      HasNextPage: true,
      dataList: [],
      noData: false,
      isReachBottom: false,
    });
    this.getDataList(true);
  },
  getDataList(isRefresh) {
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    const params = {
      Data: JSON.stringify({
        AUDIT_TYPE: 0,
        CurrentPage: this.data.CurrentPage,
        PageSize: this.data.PageSize,
        DEPT_PART: '',
        ROOM: '',
        // SelectedDate: this.data.date,
        UserCode: '',
        UserName: ''
      }),
    }
    revenueApi.GetTaskList(params).then(res => {
      wx.hideLoading();
      if (res.code === 200) {
        let dataList = []
        if (isRefresh) {
          dataList = [...res.data.DataList]
        } else {
          dataList = [...this.data.dataList, ...res.data.DataList]
        }
        let HasNextPage = res.data.HasNextPage;
        const noData = dataList.length === 0
        this.setData({
          dataList,
          HasNextPage,
          noData
        })
      }
    }).catch(_err => {
      wx.hideLoading();
    });
  },
  SetupPlan(e) {
    var info = e.currentTarget.dataset.info;
    wx.navigateTo({
      url: "/packageAudit/setup-plan/setup-plan?id=" + info.AUDIT_ID + '&name=' + info.TaskName
    })
  },
  back() {
    wx.navigateBack();
  },
})